#include "exceptions.h"
#include <cstring>

using namespace std;
using namespace MidiFile;

static const char MESS_FILE[] = "MidiReader::FileException";
static const char MESS_NOTLOADED[] = "MidiReader::NotLoadedException";
static const char MESS_INVALID[] = "MidiReader::InvalidException";

Exception::Exception(const char *message) throw (std::bad_alloc)
{
    this->message = new char[strlen(message) + 1];
    strcpy(this->message, message);
}

Exception::Exception(const Exception &other) throw ()
{
    this->message = new char[strlen(other.message) + 1];
    strcpy(this->message, other.message);
}

Exception::~Exception() throw ()
{
    delete[] message;
}

Exception & Exception::operator=(const Exception &other) throw ()
{
    if (this != &other) {
        delete[] message;
        this->message = new char[strlen(other.message) + 1];
        strcpy(this->message, other.message);
    }

    return *this;
}

const char* Exception::what() const throw ()
{
    return message;
}

FileException::FileException() :
Exception(MESS_FILE)
{
}

FileException::FileException(const char *message) :
Exception(message)
{
}

NotLoadedException::NotLoadedException() :
Exception(MESS_NOTLOADED)
{
}

NotLoadedException::NotLoadedException(const char *message) :
Exception(message)
{
}

InvalidException::InvalidException() :
Exception(MESS_INVALID)
{
}

InvalidException::InvalidException(const char *message) :
Exception(message)
{
}
